﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Audio;
using System.Xml;
using Microsoft.Xna.Framework.Content;

namespace MenuGame2DXNA
{
    public class SoundManager : InvisibleGameEntity
    {
       static List<String> ListNameSound;
       static List<SoundEffect> ListSound;
        public static bool Enable
        {
            get;

            set;

        }

        public int Volume
        {
            get;

            set;
        }
         static int nObjectInvisible;
        public SoundManager()
        {
            Volume = 100;
            ListSound = new List<SoundEffect>();
            Enable = true;
            ListNameSound = new List<String>();
            
        }
        public override void LoadContent(ContentManager content)
        {
            XmlDocument SoundXml = new XmlDocument();
            SoundXml.Load("Sounds.xml");
            XmlElement root = (XmlElement)SoundXml.SelectSingleNode("Sounds");
            foreach (XmlElement xe in root.ChildNodes)
            {
                SoundEffect temp = content.Load<SoundEffect>("Audio/"+xe.InnerText);
                ListNameSound.Add(xe.InnerText);
                ListSound.Add(temp);
            }
            nObjectInvisible = ListSound.Count;
        }
        
        public static void Play(String NameSound)
        {
            if(Enable)
            {         
               for (int i =0 ;i<nObjectInvisible;i++)
               {
                   if (ListNameSound[i] == NameSound)
                    {
                        ListSound[i].Play();

                        break;
                    }

               }
                    
                
            }
        }

        
    }
}
